package openapi.util;

import java.util.Iterator;
import java.util.Map;

import com.thoughtworks.xstream.XStream;
import com.thoughtworks.xstream.io.xml.XmlFriendlyNameCoder;
import com.thoughtworks.xstream.io.xml.XppDriver;

public class XmlUtils {
	
	@SuppressWarnings({ "rawtypes", "unchecked" })
	public static String bean2xml(Map<String, Class> clazzMap, Object bean) {
		XStream xStream = new XStream();
		for (Iterator it = clazzMap.entrySet().iterator(); it.hasNext();) {
			Map.Entry<String, Class> m = (Map.Entry<String, Class>) it.next();
			xStream.alias(m.getKey(), m.getValue());
		}
		String xml = xStream.toXML(bean);
		return xml;
	}

	public static String bean2xml(Object bean) {
		XStream xStream = new XStream(new XppDriver(new XmlFriendlyNameCoder("_-", "_")));
		xStream.autodetectAnnotations(true);
		
		String xml = xStream.toXML(bean);
		return xml;
	}
}
